Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新毎日解题06月04日 #24

Merged
merged 6 commits into from
Jun 10, 2019
Merged

更新毎日解题06月04日 #24

merged 6 commits into from
Jun 10, 2019

Conversation

wanyne-yyds
Copy link
Contributor

No description provided.

Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
```
## 参考答案
`1.暴力求解,时间复杂度O(n^2)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成:

1.暴力求解,时间复杂度O(n^2)

我们可以一次遍历gas,对于每一个gas我们依次遍历后面的gas,计算remian,如果remain一旦小于0,就说明不行,我们继续遍历下一个

这种格式

retirn -1;
```

`2.比较巧妙的方法,时间复杂度是O(n)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上


`2.比较巧妙的方法,时间复杂度是O(n)
这个方法基于两点:
2-1:如果站点i到达站点j走不通,那么从i到j之间的站点(比如k)出发一定都走不通。前提i(以及i到k之间)不会拖累总体(即remain >= 0)。
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成:

这个方法基于两点:
(注意这里有一个空行)
2-1:如果站点i到达站点j走不通,那么从i到j之间的站点(比如k)出发一定都走不通。前提i(以及i到k之间)不会拖累总体(即remain >= 0)。

`2.比较巧妙的方法,时间复杂度是O(n)
这个方法基于两点:
2-1:如果站点i到达站点j走不通,那么从i到j之间的站点(比如k)出发一定都走不通。前提i(以及i到k之间)不会拖累总体(即remain >= 0)。
2-2:如果cost总和大于gas总和,无论如何也无法走到终点,这个比较好理解。因此假如存在一个站点出发能够到达终点,其实就说明cost总和一定小于等于gas总和`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@azl397985856 azl397985856 merged commit e1b5d67 into azl397985856:master Jun 10, 2019
azl397985856 pushed a commit that referenced this pull request Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants